package sichuang.li.express100.controler;

import com.alibaba.fastjson.JSONObject;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import org.springframework.web.bind.annotation.RestController;


import java.util.HashMap;


import static sichuang.li.express100.utils.express100Utils.okHttpPostString;
import static sichuang.li.express100.utils.express100Utils.signMD5;
@RestController
public class TestExpress100 {

    /**
     * 调用快递100接口，查询物流信息
     * @param number 要查询的快递单号
     * @param expressCategory 快递单号所对应的快递公司的编码，比如 “yuantong”
     * @return
     */
    @GetMapping("/rightKuaidi100/{number}/{expressCategory}")
    public  Object rightKuaidi100(@PathVariable String number,@PathVariable String expressCategory ){
        //此处根据快递单号拿到对应的公司的编码，比如 “yuantong”,这部分代码我就不上了
        //String expressCategory = kuaidi100Service.getExpressCategory(number);
        JSONObject param = new JSONObject();
        param.put("com", expressCategory); // 公司名称
        param.put("num", number); // 订单编号
        param.put("phone", "18236750753"); // 联系电话
        param.put("from", "广东省深圳市南山区"); // 发货地址
        param.put("to", "北京市朝阳区"); // 收货地址
        param.put("resultv2", "4"); // 结果版本号
        param.put("show", "0"); // 显示选项
        param.put("order", "desc"); // 排序方式

        String jsonString = param.toString();

        String customer = "4DED8105A1339930FDE107CAA7748C19";
        String key = "MEviEJDk2185";
        String sign = signMD5(param + key + customer);
        HashMap params = new HashMap();
        params.put("param", jsonString);
        params.put("sign", sign.toUpperCase());
        params.put("customer", customer);

        return okHttpPostString("http://poll.kuaidi100.com/poll/query.do", params);
    }

}
